package com.itheima.qingcheng.controller;

import com.itheima.qingcheng.pojo.Dto.LoginDto;
import com.itheima.qingcheng.pojo.Result;
import com.itheima.qingcheng.pojo.Vo.LoginVo;
import com.itheima.qingcheng.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangzhen
 * @version 1.0
 * @date 2025/1/21 8:53
 */
@Slf4j
@RestController
@RequestMapping("/login")
public class UserController {
    @Autowired
   private UserService userService;
    @PostMapping
    public Result login(@RequestBody LoginDto loginDto){
            log.info("员工来登录啦 , {}", loginDto);
            LoginVo loginVo = userService.login(loginDto);
        if(loginVo != null){
            String username = loginVo.getUsername();
            String token = loginVo.getToken();
                return   new Result(1,username,token);
            }
            return Result.error("用户名或密码错误~");
        }

}